<?php
namespace web\admin\controller;
class Brank extends Common
{
	//动作
	private $db;

	public function __construct()
	{
		parent::__construct();
		$this->db = new \system\model\Brank();
	}

	public function index()
	{
		$data = $this->db->getAll();
		View::with('data', $data);
		View::make();
	}

	public function add()
	{
		if (IS_POST) {
			//如果添加不通过
			if (!$this->db->store()) {
				//获取错误
				message($this->db->getError(), 'back', 'error');
			} else {
				message('添加成功', u('index', ['bid' => $_POST['bid']]), 'success');
			}
		}
		View::make();
	}

	public function edit()
	{
		if (IS_POST) {
			if ($this->db->edit()) {
				message('修改成功', u('index', ['bid' => $_POST['bid']]), 'success');
			} else {
				message($this->db->getError(), 'back', 'error');
			}
		}
		$bid = q('get.bid', 0, 'intval');
		$oldData = $this->db->where('bid',$bid)->first();
//		p($oldData);
		//分配变量并显示
		View::with('oldData', $oldData);
		View::make();
	}

	/**
	 * 删除
	 */
	public function del()
	{
		$bid = q('get.bid', 0, 'intval');
		$this->db->where('bid', $bid)->delete();
		message('操作成功', u('index'), 'success');
	}
}

